package com.one.common.core.domain;


import com.one.common.core.enums.ResultCode;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
public class TableDataInfo {
    /**
     * 消息状态码
     */
    private int code;

    /**
     * 消息内容
     */
    private String msg;

    /**
     * 数据总数
     */
    private long total;

    /**
     * 列表数据
     */
    private List<?> rows;

    /**
     * 表格数据对象
     */
    public TableDataInfo(){
    }

    // 未查询到数据时调用
    public static TableDataInfo empty(){
        TableDataInfo list = new TableDataInfo();
        list.setCode(ResultCode.SUCCESS.getCode());
        list.setMsg(ResultCode.SUCCESS.getMsg());
        list.setRows(new ArrayList<>());
        list.setTotal(0);

        return list;
    }

    //查询到数据时调用
    public static TableDataInfo success(List<?> list1, long total){
        TableDataInfo list = new TableDataInfo();
        list.setCode(ResultCode.SUCCESS.getCode());
        list.setMsg(ResultCode.SUCCESS.getMsg());
        list.setRows(list1);
        list.setTotal(total);

        return list;
    }

}
